<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.dic.service.UserService"%>
<%@ page import="com.dic.dao.*"%>
<%@ page import="com.dic.dao.model.*"%>


<% 
   request.setCharacterEncoding("utf-8");
   response.setCharacterEncoding("utf-8");
   
   String username=request.getParameter("username").trim();
   String role=request.getParameter("role").trim();
   String oldkey=request.getParameter("oldkey").trim();
   String newkey=request.getParameter("newkey").trim();
   
   HashMap<String,String> hm=new HashMap<String,String>();
   hm.put("username", username);
   hm.put("role", role);
   
   UserService ser1 = new UserService();
   User user2= ser1.getPassword(hm);   //获取原始密码
   //System.out.println(user2.getPassword());
   boolean flag=false;
   if(oldkey.equals(user2.getPassword().toString())){  //判断原始密码是否正确
       flag=true;
   }
   if(flag==true){
      UserService ser2 = new UserService();
      User user1=new User(username,newkey,role);
      int updateflag=ser2.updatePw(user1);
   	  if(updateflag==1)
     	  out.print("{'result':'success'}");
      else 
     	  out.print("{'result':'fail'}");
   }else{
      out.print("{'result':'failp'}");
   }
   
   




%>